﻿using System;
using System.Windows.Forms;
using Kassandra.WindowsUI.Presenters;

namespace Kassandra.WindowsUI
{
    public partial class frmAddNewImage : Form, IAddNewImageView
    {
        private readonly AddNewImagePresenter _presenter;

        public frmAddNewImage()
        {
            InitializeComponent();

            _presenter = new AddNewImagePresenter(this);
            btnAdd.Click += _presenter.SaveClick;
            btnCancel.Click += Cancel;
            btnBrowseSourceFile.Click += Browse;
        }

        private void Browse(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog();
            dialog.Multiselect = false;
            dialog.DefaultExt = "TIF (*.tif)|*.tif";
            dialog.Filter = "TIF (*.tif)|*.tif";
            dialog.Title = "Select image to add";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                txtSourceFile.Text = dialog.FileName;
            }
        }

        private void Cancel(object sender, EventArgs e)
        {
            this.Close();
        }

        public void ShowMessage(string message)
        {
            MessageBox.Show(message);
        }

        public char? AssociatedCharacter
        {
            get
            {
                if (txtCharacter.Text.ToCharArray().Length > 0)
                {
                    return txtCharacter.Text.ToCharArray()[0];
                }
                return null;
            }
        }

        public string SourceFile
        {
            get { return txtSourceFile.Text; }
        }
    }
}